<?php
header("content-type:text/html;charset=utf8");

$uname = $_POST["uname"];
$pass = $_POST["pass"];
$phone = $_POST["phone"];
$email = $_POST["email"];

if (isset($uname, $pass, $phone, $email)) {

    $con = mysqli_connect("localhost", "root", "root", "one");
    mysqli_query($con, "set names utf8");

    $res = mysqli_query($con, "select * from information where username='{$uname}'");
    $row = mysqli_fetch_assoc($res);

    $res1 = mysqli_query($con, "select * from information where phone='{$phone}'");
    $row1 = mysqli_fetch_assoc($res1);

    $res2 = mysqli_query($con, "select * from information where email='{$email}'");
    $row2 = mysqli_fetch_assoc($res2);

    if (!empty($row)) {
        $arr = [
            "status" => 1,
            "msg" => "用户名被占用了"
        ];
        echo json_encode($arr);
    } elseif (!empty($row1)) {
        $arr = [
            "status" => 101,
            "msg" => "该手机号已被注册"
        ];
        echo json_encode($arr);
    } elseif (!empty($row2)) {
        $arr = [
            "status" => 102,
            "msg" => "该邮箱已被注册"
        ];
        echo json_encode($arr);
    } else {
        $res = mysqli_query($con, "insert information(username,password,phone,email) values('{$uname}','{$pass}','{$phone}','{$email}')");
        if ($res) {
            $arr = [
                "status" => 2,
                "msg" => "注册成功"
            ];
            echo json_encode($arr);
        } else {
            $arr = [
                "status" => 3,
                "msg" => "注册失败"
            ];
            echo json_encode($arr);
        }
    }
} else {
    $arr = [
        "status" => 4,
        "msg" => "非法请求"
    ];
    echo json_encode($arr);
}
